package com.sx.micowell.framework.model

import com.example.mvvm.base.data.MutableLiveListData
import com.example.mvvm.base.vm.BaseViewModel
import com.example.mvvm.until.LogUtils
import com.example.mvvm.until.SPUtils
import com.example.mvvm.until.ToastUtils
import com.miloyu.modelnet.network.ApiResponse
import com.miloyu.modelnet.network.HttpClient
import com.miloyu.modelnet.network.service.IApiService
import com.miloyu.modelnet.network.tools.RxUtils
import com.miloyu.modelnet.response.SysNotice
import com.miloyu.modelnet.response.SysNoticesWrap
import com.sx.micowell.framework.app.SPKey
import java.util.HashMap

/**
 * @Author: YY
 * @Time: 2021/8/13
 * @Describe TODO
 */
class MineNewsModel: BaseViewModel() {

    var noticeListData: MutableLiveListData<SysNotice> = MutableLiveListData<SysNotice>()

    /**
     * 获取消息公告
     */
    fun getNotice() {

        HttpClient.instance.apiService
            .getNotice()
            .compose(RxUtils.compose())
            .subscribe(object : ApiResponse<SysNoticesWrap>() {

                override fun success(data: SysNoticesWrap?, msg: String?) {
                    LogUtils.d("getNotice ${data?.sysNotices?.size}")
                    noticeListData.addData(data?.sysNotices)
                }

                override fun onFail(e: Throwable?, errorMsg: String?) {
                    ToastUtils.showShort("$errorMsg")
                }
            })
    }
}